n = input()
if 999 < int(n) < 10000:
    s = [n[0], n[1], n[2], n[3], n[:2], n[0] + n[2], n[0] + n[3], n[1] + n[2], \
         n [2:], n[1] + n[3], n[1:], n[:2] + n[3], n[0] + n[2:], n[:3], n]
    max_prost = 0
    for i in s:
        for j in range(2, int(int(i)**0.5) + 1):
            if int(i) % j == 0:
                break
        else:
            if max_prost < int(i):
                max_prost = int(i)
    print(max_prost)
else:
    print(0)